package com.wander.netty.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class ServerHanlder extends SimpleChannelInboundHandler<Object> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
        String message = ctx.channel().remoteAddress() + ": " + msg;
        System.out.println("收到客户端消息：" + message);
        ctx.channel().writeAndFlush(message);
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        System.out.println("客户端已连接：" + ctx.channel().remoteAddress());
    }
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }

}
